home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1990-94 Silicon Graphics, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that the name of Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
- * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
- /*
- * Copyright (C) 1990-93 Silicon Graphics, Inc.
- *
- _______________________________________________________________________
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- |
- | $Revision: 1.1013 $
- |
- | Classes:
- | MyColorPatch
- |
- | Author(s) : Alain Dumesny
- |
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- _______________________________________________________________________
- */
-
- #if DEBUG
- #include <stream.h>
- #endif
-
- #include "MyUIRegion.h"
- #include "MyColorPatch.h"
-
- #include <GL/gl.h>
-
-
- /*
- * Defines
- */
-
- #define SIDE (UI_THICK + 2 + UI_THICK)
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Public constructor - build the widget right now
- //
- MyColorPatch::MyColorPatch(
- Widget parent,
- const char *name,
- SbBool buildInsideParent)
- : SoXtGLWidget(
- parent,
- name,
- buildInsideParent,
- SO_GLX_RGB,
- FALSE) // tell GLWidget not to build just yet
- //
- ////////////////////////////////////////////////////////////////////////
- {
- // In this case, this component is what the app wants, so buildNow = TRUE
- constructorCommon(TRUE);
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // SoEXTENDER constructor - the subclass tells us whether to build or not
- //
- MyColorPatch::MyColorPatch(
- Widget parent,
- const char *name,
- SbBool buildInsideParent,
- SbBool buildNow)
- : SoXtGLWidget(
- parent,
- name,
- buildInsideParent,
- SO_GLX_RGB,
- FALSE) // tell GLWidget not to build just yet
- //
- ////////////////////////////////////////////////////////////////////////
- {
- // In this case, this component may be what the app wants,
- // or it may want a subclass of this component. Pass along buildNow
- // as it was passed to us.
- constructorCommon(buildNow);
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Called by the constructors
- //
- // private
- //
- void
- MyColorPatch::constructorCommon(SbBool buildNow)
- //
- //////////////////////////////////////////////////////////////////////
- {
- // init local vars
- color[0] = color[1] = color[2] = 0;
- setGlxSize( SbVec2s(40, 40) ); // default size
-
- // Build the widget tree, and let SoXtComponent know about our base widget.
- if (buildNow) {
- Widget w = buildWidget(getParentWidget());
- setBaseWidget(w);
- }
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Dummy virtual destructor.
- //
- MyColorPatch::~MyColorPatch()
- //
- ////////////////////////////////////////////////////////////////////////
- {
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Routine which draws the color patch
- //
- // Use: virtual public
-
- void
- MyColorPatch::redraw()
- //
- ////////////////////////////////////////////////////////////////////////
- {
- if (! isVisible())
- return;
-
- glXMakeCurrent(getDisplay(), getNormalWindow(), getNormalContext());
-
- // draw border
- SbVec2s size = getGlxSize();
- drawDownUIRegion(0, 0, size[0]-1, size[1]-1);
-
- // draw the patch color
- glColor3fv(color.getValue());
- glRecti(SIDE, SIDE, size[0] - SIDE, size[1] - SIDE);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Sets the patch color
- //
- // Use: public
-
- void
- MyColorPatch::setColor(const SbColor &rgb)
- //
- ////////////////////////////////////////////////////////////////////////
- {
- // save color
- color = rgb;
-
- // now show the color change
- if (! isVisible())
- return;
- glXMakeCurrent(getDisplay(), getNormalWindow(), getNormalContext());
-
- glColor3fv(color.getValue());
- SbVec2s size = getGlxSize();
- glRecti(SIDE, SIDE, size[0] - SIDE, size[1] - SIDE);
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // This routine is called when the window size has changed.
- //
- // Use: virtual private
-
- void
- MyColorPatch::sizeChanged(const SbVec2s &newSize)
- //
- ////////////////////////////////////////////////////////////////////////
- {
- // reset projection
- glXMakeCurrent(getDisplay(), getNormalWindow(), getNormalContext());
- glViewport(0, 0, newSize[0], newSize[1]);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, newSize[0], 0, newSize[1], -1, 1);
- }
-